package com.kingdee.eas.mx.docs.imp.lc.app;

import org.apache.log4j.Logger;
import javax.ejb.*;
import java.rmi.RemoteException;
import java.sql.SQLException;

import com.kingdee.bos.*;
import com.kingdee.bos.util.BOSObjectType;
import com.kingdee.bos.metadata.IMetaDataPK;
import com.kingdee.bos.metadata.rule.RuleExecutor;
import com.kingdee.bos.metadata.MetaDataPK;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.framework.ejb.AbstractEntityControllerBean;
import com.kingdee.bos.framework.ejb.AbstractBizControllerBean;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.dao.IObjectCollection;
import com.kingdee.bos.service.ServiceContext;
import com.kingdee.bos.service.IServiceContext;

import java.lang.String;
import java.math.BigDecimal;

import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.eas.base.codingrule.CodingRuleManagerFactory;
import com.kingdee.eas.base.codingrule.ICodingRuleManager;
import com.kingdee.eas.basedata.org.CompanyOrgUnitInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.common.SysContextConstant;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.eas.fdc.basedata.FDCSQLBuilder;
import com.kingdee.eas.framework.app.BillBaseControllerBean;
import com.kingdee.eas.mx.basedata.enums.StateEnum;
import com.kingdee.eas.mx.docs.imp.lc.AssureCollection;
import com.kingdee.eas.mx.docs.imp.lc.AssureInfo;
import com.kingdee.eas.mx.imp.ipo.ImpPurContractSelfInfo;
import com.kingdee.eas.util.SysUtil;
import com.kingdee.eas.util.app.DbUtil;
import com.kingdee.eas.util.client.MsgBox;

import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.eas.framework.CoreBaseCollection;
import com.kingdee.eas.framework.CoreBillBaseCollection;
import com.kingdee.eas.framework.BillBaseCollection;
import com.kingdee.eas.framework.CoreBaseInfo;
import com.kingdee.eas.framework.ObjectBaseCollection;
import com.kingdee.jdbc.rowset.IRowSet;

public class AssureControllerBean extends AbstractAssureControllerBean
{
    private static Logger logger =
        Logger.getLogger("com.kingdee.eas.mx.docs.imp.lc.app.AssureControllerBean");
    
    protected IObjectPK _submit(Context ctx, IObjectValue model)
	throws BOSException, EASBizException {
    	AssureInfo info = (AssureInfo)model;
    	info.setState(StateEnum.submit);
		return super._submit(ctx, info);
    }
    protected IObjectPK _save(Context ctx, IObjectValue model) throws BOSException, EASBizException {
    	AssureInfo info = (AssureInfo)model;
    	if(info.getState().equals(StateEnum.addNew)||info.getState().equals(StateEnum.save)){
    		if(info.getNumber()==null||info.getNumber().equals("")){
    			CompanyOrgUnitInfo company = (CompanyOrgUnitInfo)ctx.get(SysContextConstant.COMPANYINFO);
        		String companyId = company.getId().toString();
    	        ICodingRuleManager codeRuleMgr = null;
    	        codeRuleMgr  = CodingRuleManagerFactory.getLocalInstance(ctx);
    	        if(codeRuleMgr.isExist(info, companyId)){
    	        	info.setNumber(codeRuleMgr.getNumber(info, companyId));
    	        }
    		}
    		info.setState(StateEnum.save);
    	}
    	
    	return super._save(ctx, model);
    }
//    protected void _unAudit(Context ctx, IObjectValue model)
//		throws BOSException {
//		ImpPurContractSelfInfo info = (ImpPurContractSelfInfo)model;
//		info.setState(StateEnum.notAuditing);
//		try {
//			super._save(ctx, model);
//		} catch (EASBizException e) {
//			e.printStackTrace();
//		}
//	}
}